/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author ZER0
 */
public class Create_account_Sever {

    String user = ConnectSQL.user;
    String pass1 = ConnectSQL.pass;
    String ulr =ConnectSQL.ulr;
    String DriverClass =ConnectSQL.DriverClass;
    Connection con = null;

    public boolean InsertAccount(String idu, String ide, String username, String pass, String table, String cn1, String cn2, String cn3, String cn4) {
        boolean rsx = false;
        try {
            // add du lieu vao database
            Class.forName(DriverClass);
            con = DriverManager.getConnection(ulr, user, pass1);
            String sql = "INSERT INTO " + table + "(" + cn1 + "," + cn2 + "," + cn3 + "," + cn4 + ") VALUES('" + idu + "', '" + ide + "', '" + username + "', '" + pass + "')";
            PreparedStatement Psttm = con.prepareStatement(sql);
            Psttm.executeUpdate();
            rsx = true;
        } catch (SQLException ex) {
            Logger.getLogger(Create_account_Sever.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Create_account_Sever.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            //kiem tra ham co gia tri de add ko ,neu ko co thi dong ket noi
            if (con != null) {
                try {
                    con.close();
                    System.out.println("Dong ket noi");
                } catch (Exception e) {
                }
            }
        }
        return rsx;
    }

    public void ShowTable(String id, String sa1, String sa2, JTable sa, String t1, String t2, String t3) {
        //khai bao model de hien thi bang
        DefaultTableModel listTableModel = new DefaultTableModel();
        Vector r = new Vector();
        Vector tableR1 = new Vector();
        r.add(id);
        r.add(sa1);
        r.add(sa2);
        tableR1.add(r);
        //goi mo do hien thi thong tin ra bang
        Vector<String> columnNames = new Vector<String>();
        columnNames.addElement("" + t1 + "");
        columnNames.addElement("" + t2 + "");
        columnNames.addElement("" + t3 + "");
        sa.setModel(listTableModel);
        listTableModel.setDataVector(tableR1, columnNames);
    }
}
